# -*- coding: utf-8 -*-
"""
@author: dengpanxiao(@126.com)

@file: statistic.py

@time: 17/8/26 下午8:10

@desc: 统计量

"""
import math


# 均值
def mean(x):
    if not x or len(x) == 0:
        return x
    return sum(x)/float(len(x))

# 方差
def var(x):
    if not x or len(x) == 0:
        return x
    x_mean = mean(x)
    res = 0
    for _ in x:
        res += (_ - x_mean) ** 2
    res /= float(len(x))
    return res


# 标准差
def std_var(x):
    if not x or len(x) == 0:
        return x
    return math.sqrt(var(x))


# 范数
# 特征值
# 特征向量